nition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* removeNthFromEnd(ListNode* head, int n) 
    {
        ListNode* phead = new ListNode;
        phead->next = head;

        ListNode* cur = head;
        ListNode* prev = phead;
        ListNode* index = head;


        while (n--)
        {
            index = index-> next;
        }

        while(index)
        {
            prev = cur;
            index = index-> next;
            cur = cur-> next;
        }

        prev-> next = cur-> next;

        delete cur; 
        cur = nullptr;
        prev = phead -> next;
        delete phead;
        return prev;


    }
};
